package com.kfyang.manualgear.generator.declare;

import com.squareup.javapoet.FieldSpec;
import com.squareup.javapoet.MethodSpec;
import com.squareup.javapoet.TypeName;
import com.squareup.javapoet.TypeSpec;
import com.kfyang.manualgear.struct.MethodInfo;

import java.util.*;

public class ClassWrapper {
    /**
     * 类构造器
     */
    private final TypeSpec.Builder classBuilder;
    /**
     * Mapper文件的方法信息
     */
    public Map<String, MethodInfo> methodInfoMap;
    public Map<String, MethodInfo.Frag> globalFragMap;
    /**
     * 构造器哈希表
     */
    private final Map<TypeName, Set<String>> constructMap = new HashMap<>();

    public ClassWrapper(TypeSpec.Builder classBuilder) {
        this.classBuilder = classBuilder;
    }

    public void addField(FieldSpec fieldSpec) {
        classBuilder.addField(fieldSpec);
    }

    public void addMethods(List<MethodSpec> methods) {
        classBuilder.addMethods(methods);
    }

    public Set<String> getConstructSet(TypeName typeName) {
        return constructMap.computeIfAbsent(typeName, k -> new HashSet<>());
    }

    public TypeSpec build() {
        return classBuilder.build();
    }
}
